package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Returngoods;
import com.li.drug.mapper.ReturngoodsMapper;
import com.li.drug.service.ReturngoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

@Service
public class ReturngoodsServiceImpl extends ServiceImpl<ReturngoodsMapper, Returngoods> implements ReturngoodsService {

    @Autowired
    ReturngoodsMapper returngoodsMapper;

    /**
     * 分页查询对象
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param param 查询参数
     * @return
     */
    @Override
    public Page<Returngoods> selectReturngoodsPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Returngoods> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        Page<Returngoods> page = new Page<>(pageNum,pageSize);
        return returngoodsMapper.selectPage(page,wrapper);
    }

    @Override
    public int addReturngoods(Returngoods returngoods) {
        return returngoodsMapper.insert(returngoods);
    }

    @Override
    public int editReturngoods(Returngoods returngoods) {
       return returngoodsMapper.updateById(returngoods);
    }

    @Override
    public Returngoods getReturngoodsById(Integer id) {
        return returngoodsMapper.selectById(id);
    }

    @Override
    public int delReturngoodsById(Integer id) {
        return returngoodsMapper.deleteById(id);
    }
}
